
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
    #pragma hdrstop
#endif

// for all others, include the necessary headers (this file is usually all you
// need because it includes almost all "standard" wxWidgets headers)
#ifndef WX_PRECOMP
    #include "wx/wx.h"
#endif

#include "DRect.h"



DRect::DRect(void)
{
	m_pen.SetColour(255, 0, 0);
	m_brush.SetColour(255, 255, 255);
}

DRect::DRect(int x, int y, int width, int height)
{
	m_pen.SetColour(255, 0, 0);
	m_brush.SetColour(255, 255, 255);

	m_x = x;
	m_y = y;
	m_width = width;
	m_height = height;	
}

DRect::~DRect(void)
{
	//
}

void DRect::Draw(wxDC *dc)
{
	if(this->m_selected == TRUE)
	{
		this->SetDrawingTools(dc);
		dc->SetPen(wxPen(wxColor(0, 0, 255), 1, wxDOT));
		dc->DrawRectangle(this->m_x, this->m_y, this->m_width, this->m_height);
	}
	else
	{
		this->SetDrawingTools(dc);
		dc->DrawRectangle(this->m_x, this->m_y, this->m_width, this->m_height);
	}
}

bool DRect::PointInside(wxPoint *pnt)
{
	int n_x, n_y, n_w, n_h;

	if(m_width < 0)
	{
		n_x = m_x + m_width;
		n_w = -m_width;
	}

	else
	{
		n_x = m_x;
		n_w = m_width;
	}

	if(m_height < 0)
	{
		n_y = m_y + m_height;
		n_h = -m_height;
	}
	else
	{
		n_y = m_y;
		n_h = m_height;
	}

	wxRect rct(n_x, n_y, n_w, n_h);

	if(rct.Inside(*pnt) == true)
		return TRUE;
	else
		return FALSE;
}

float DRect::GetArea()
{
	return (float)(m_height * m_width);
}

void DRect::SetCoords(int x, int y, int width, int height)
{
	m_x = x;
	m_y = y;
	m_width = width;
	m_height = height;
}

void DRect::ConvertToText(wxString *str)
{
	*str << wxT("rect\t") << this->m_x << wxT("\t") << m_y << wxT("\t") << this->m_width << wxT("\t") << m_height << wxT("\n");
}

wxPoint DRect::GetTopLeft(void)
{
	return wxPoint(m_x, m_y);
}

wxPoint DRect::GetBottomRight()
{
	return wxPoint(m_x + m_width, m_y + m_height);
}